import time
import os


import allure
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By

from Page.JieDan_Page import JieDan_Page
from Page.Login_Page import Login_Page
from Tools.Tools import log


@pytest.fixture(scope="function")
def Case():
    #测试前准备
    with allure.step("启动浏览器"):
        driver=webdriver.Edge()
        driver.maximize_window()
    yield driver #返回dirver对象供测试使用
    with allure.step("关闭浏览器"):
        time.sleep(3)
        driver.quit()
        print('测试结束')

@allure.feature("登录-接单员列表")
class TestLook:
    @allure.story("接单员列表功能")
    @allure.title("测试管理员登录-接单员列表一系列功能")
    @allure.severity(allure.severity_level.CRITICAL)
    def test_01_login(self,Case):
        with allure.step("打开登录页面"):
            po=JieDan_Page(Case)
            po.open_url('http://10.59.9.21/dist#/login')
            allure.attach(Case.get_screenshot_as_png(),name="登录页面截图",
                          attachment_type=allure.attachment_type.PNG)
            log.info('打开登录页面')
        with allure.step("输入账号密码"):
            po.username('admin')
            po.password('qwe123123')
            allure.attach(Case.get_screenshot_as_png(),name='输入账号密码后截图',
                          attachment_type=allure.attachment_type.PNG)
            log.info('输入账号密码')
        with allure.step("点击登录"):
            po.login()
            allure.attach(Case.get_screenshot_as_png(),name='点击登录后截图',
                          attachment_type=allure.attachment_type.PNG)
            time.sleep(2)
            # dy_login=po.find_element((By.XPATH,'/html/body/div/div/div[2]/div/div[1]/ul/li[4]/ul/li[2]/i')).text
            # assert '接单员列表'==dy_login,f'断言失败{dy_login}'
            time.sleep(2)
            log.info('登录后的页面')
        with allure.step("点击接单员列表"):
            po.jiedan()
            allure.attach(Case.get_screenshot_as_png(),name='点击接单员列表后截图',
                          attachment_type=allure.attachment_type.PNG)
            log.info('点击接单员列表')
            time.sleep(2)
        with allure.step('点击每页10条'):
            po.ye()
            allure.attach(Case.get_screenshot_as_png(), name='点击每页10条后截图',
                          attachment_type=allure.attachment_type.PNG)
            log.info('点击每页10条')
        with allure.step('每页30条'):
            po.tiao()
            allure.attach(Case.get_screenshot_as_png(), name='点击每页30条后截图',
                          attachment_type=allure.attachment_type.PNG)
            log.info('选择每页30条')
        with allure.step('点击查看数据'):
            po.look()
            allure.attach(Case.get_screenshot_as_png(), name='点击查看数据后截图',
                          attachment_type=allure.attachment_type.PNG)
            log.info('点击查看数据')



# if __name__ == '__main__':
#     # 生成Allure原始数据
#     pytest_args = [
#         'E:/GXPycharm/PythonObject/Help_PO_Ul/Case/TestLook.py',  # 测试用例目录
#         '-v',  # 详细输出
#         '--alluredir=./Report/allure_raw'  # 指定Allure结果目录
#     ]
#     pytest.main(pytest_args)
#
#     # 检查allure_raw目录是否存在
#     os.path.exists('./Report/allure_raw')
#     # 生成HTML报告（需提前安装Allure命令行工具）
#     os.system('allure generate ./Report/allure_raw -o ./Report/allure_html --clean')
#     # 自动打开报告
#     print("报告生成成功，正在打开...")
#     os.system('allure open ./Report/allure_html')
#
